package com.jzzzb.debug.beanfactory;

import com.jzzzb.debug.mapper.UserMapper;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class UserFactoryBean implements FactoryBean<UserMapper> {
	@Override
	public UserMapper getObject() {
		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		Class[] classes = {UserMapper.class};
		InvocationHandler handler = (proxy, method, args) -> "你被代理了 " + method.getName();
		return (UserMapper) Proxy.newProxyInstance(classLoader, classes, handler);
	}

	@Override
	public Class<?> getObjectType() {
		return UserMapper.class;
	}
}
